From 408920d438af56d8d83e6a78065608723057c325 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 7 Sep 2015 21:37:07 +0200 Subject: [PATCH] window: Add gtk_widget_class_set_css_name() This is to replace using class names as CSS names. --- docs/reference/gtk/gtk3-sections.txt | 2 ++ gtk/gtkwidget.c | 47 +++++++++++++++++++++++++++- gtk/gtkwidget.h | 6 ++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index d6274d75f5..360a69c7e8 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -5602,6 +5602,8 @@ gtk_widget_get_action_group gtk_widget_get_path gtk_widget_get_style_context gtk_widget_reset_style +gtk_widget_class_get_css_name +gtk_widget_class_set_css_name gtk_requisition_new diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 4ae6e2b15c..df34d1068b 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -487,6 +487,7 @@ struct _GtkWidgetClassPrivate GtkWidgetTemplate *template; GType accessible_type; AtkRole accessible_role; + const char *css_name; }; enum { @@ -4365,7 +4366,10 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class) priv->cssnode = gtk_css_widget_node_new (widget); gtk_css_node_set_state (priv->cssnode, GTK_STATE_FLAG_DIR_LTR); /* need to set correct type here, and only class has the correct type here */ - gtk_css_node_set_widget_type (priv->cssnode, G_TYPE_FROM_CLASS (g_class)); + if (GTK_WIDGET_GET_CLASS (widget)->priv->css_name) + gtk_css_node_set_name (priv->cssnode, GTK_WIDGET_GET_CLASS (widget)->priv->css_name); + else + gtk_css_node_set_widget_type (priv->cssnode, G_TYPE_FROM_CLASS (g_class)); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; priv->style = gtk_widget_get_default_style (); @@ -16312,6 +16316,47 @@ gtk_widget_clear_path (GtkWidget *widget) g_object_set_qdata (G_OBJECT (widget), quark_widget_path, NULL); } +/** + * gtk_widget_class_set_css_name: + * @widget_class: class to set the name on + * @name: name to use + * + * Sets the name to be used for CSS matching of widgets. + * + * If this function is not calles for a given class, the name + * of the parent class is used. + **/ +void +gtk_widget_class_set_css_name (GtkWidgetClass *widget_class, + const char *name) +{ + GtkWidgetClassPrivate *priv; + + g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class)); + g_return_if_fail (name != NULL); + + priv = widget_class->priv; + + priv->css_name = g_intern_string (name); +} + +/** + * gtk_widget_class_get_css_name: + * @widget_class: class to set the name on + * + * Gets the name used by this class for matching in CSS code. See + * gtk_widget_class_set_css_name() for details. + * + * Returns: the CSS name of the given class. + */ +const char * +gtk_widget_class_get_css_name (GtkWidgetClass *widget_class) +{ + g_return_val_if_fail (GTK_IS_WIDGET_CLASS (widget_class), NULL); + + return widget_class->priv->css_name; +} + void _gtk_widget_style_context_invalidated (GtkWidget *widget) { diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index c725fcba8c..6aeda831d4 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -1302,6 +1302,12 @@ GtkStyleContext * gtk_widget_get_style_context (GtkWidget *widget); GDK_AVAILABLE_IN_ALL GtkWidgetPath * gtk_widget_get_path (GtkWidget *widget); +/*GDK_AVAILABLE_IN_3_20*/ +void gtk_widget_class_set_css_name (GtkWidgetClass *widget_class, + const char *name); +/*GDK_AVAILABLE_IN_3_20*/ +const char * gtk_widget_class_get_css_name (GtkWidgetClass *widget_class); + GDK_AVAILABLE_IN_3_4 GdkModifierType gtk_widget_get_modifier_mask (GtkWidget *widget, GdkModifierIntent intent); -- 2.30.2